package com.sw.c.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javazoom.jl.decoder.JavaLayerException;
import javazoom.jl.player.Player;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

@Api(tags = "音频相关接口")
@RestController
@RequestMapping("/yp")
public class AudioController {

    @ApiOperation("播放音乐文件")
    @GetMapping("/video/yy")
    public void playMusic(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String filePath = "D:/tomcat/apache-tomcat-8.0.50/webapps/alsoLowLawFirms/mobile/images/test.mp3";

        try {
            FileInputStream inputStream = new FileInputStream(filePath);
            Player player = new Player(inputStream);

            player.play();

            System.out.println("音乐播放完毕！");
        } catch (FileNotFoundException | JavaLayerException e) {
            System.err.println("音乐播放失败：" + e.getMessage());
        }
    }
}
